// 构建的核心逻辑
const fs = require('fs')
const { Transform } = require('stream')
exports.default = () => {
    // 读取
    const read = fs.createReadStream('css/normalize.css')
    // 转换

    // 转换流
    const transform = new Transform({
        transform: (chunk, encoding, callback) => {
            const input = chunk.toString()
            const output = input.replace(/\s+/g, '').replace(/\/\*.+?\*\//g, '')
            callback(null, output)
        }
    })
    // 写入
    const write = fs.createWriteStream('css/normalize.min.css')

    read
        .pipe(transform)
        .pipe(write)
    return read
}